<?php
/**
 * <OXmlValidator>
 *  Copyright (C) <2011>  <Omar Teodoro Alegre>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * 
 * ********************************************************
 * ********************************************************
 *                    OXmlValidator
 * ********************************************************
 * ********************************************************
 * 
 * @version 1.0
 * @created 28-ago-2011 07:07:53 p.m.
 * @author Omar Teodoro Alegre - alegreomarteodoro@yahoo.com.ar
 *  Corrientes, Argentina.
 */

class OXmlValidator {
	
	function __construct() {
	
	}
	
	/**
	 * Verifica un nombre ; 
	 * Se utiliza tanto para verificar el nombre de un elemento o de un atributo ;
	 * Corrije automaticamente el nombre en caso de que los nombres no sean validos.
	 * @param String $name - Nombre del elemento o del atributo.
	 * @return String - Nombre validado y corregido si fue necesario.
	 */
	public static function checkName( $name )
	{
		return ereg_replace( "(^xml|^XML|^[0-9]+|-|(:)+|\.|[[:space:]])+" , "_" , $name );	
	}
	
	/**
	 * Verifica el valor de un elemento ;
	 * Si presenta caracteres no permitidos retorna texto encerrado en CDATA.
	 * @param Var $value
	 * @return String - Valor.
	 */
	public static function checkValue( $value )
	{
		if( strpos( $value , '<' ) != false || 
			strpos( $value , '>' ) != false || 
			strpos( $value , '&' ) != false ||
			strpos( $value , '"' ) != false ||
			strpos( $value , "'" ) != false )
			return '<![CDATA[' . $value . ']]>';
		return $value;
	}
}

?>